﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
using System.Text.RegularExpressions;

namespace TextMIS
{
    public partial class frmResultFind : Form
    {
        public frmResultFind()
        {
            InitializeComponent();
        }

        public static string userName;
        public static string strSql;
        public static string String;
        SqlConnection conn;
        SqlDataAdapter da;

        private void frmResultFind_Load(object sender, EventArgs e)
        {
            userName = frmLogin.userName;
            conn = new
SqlConnection(frmLogin.SQLstr);
            listView1.GridLines = true;
            listView1.FullRowSelect = true;
            listView1.View = View.Details;
            listView1.Scrollable = true;
            listView1.MultiSelect = false;
            listView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            lbl.Text = "您的体检项目  的体检结果如下";
            if (frmLogin.userRight == "普通用户")
            {
                strSql = "select RegisterID, Pname,BranchName ,ItemName, Result from viewPI_tab where Username = '" + userName + "'";
                this.ShowInfo();
            }
            else
            {
                strSql = "select RegisterID, Pname,BranchName ,ItemName, Result from viewPI_tab ";
                this.ShowInfo();
            }
            txtResult.Enabled = false;
        }

        private void HeaderList()
        {
            listView1.Columns.Add("注册编号", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("用户姓名", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("体检部门", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("体检项目", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("体检结果", 120, HorizontalAlignment.Left);

        }

        private void ShowInfo()
        {
            try
            {
                listView1.Clear();
                da = new SqlDataAdapter(strSql, conn);

                DataTable dt = new DataTable();
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                int count = da.Fill(dt);
                conn.Close();

                HeaderList();
                foreach (DataRow dr in dt.Rows)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.SubItems.Clear();
                    lvi.SubItems[0].Text = dr[0].ToString();
                    lvi.SubItems.Add(dr[1].ToString());
                    lvi.SubItems.Add(dr[2].ToString());
                    lvi.SubItems.Add(dr[3].ToString());
                    lvi.SubItems.Add(dr[4].ToString());
                    listView1.Items.Add(lvi);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnCheck_Click(object sender, EventArgs e)
        {
            txtResult.Text = listView1.SelectedItems[0].SubItems[4].Text.ToString();
            lbl.Text = "您的体检项目 " + listView1.SelectedItems[0].SubItems[3].Text.ToString().Trim() + " 的体检结果如下";
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
